package com.d2rv.model;

import com.d2rv.offscreen.OffScreen3D;
import processing.core.PApplet;
import processing.core.PVector;
import saito.objloader.BoundingBox;
import saito.objloader.OBJModel;
import saito.objloader.OBJModelLite;

/**
 * Abstract class of an obj model : describes principal information of an obj
 * model
 *
 * @author Darrieutort A., Dupouy A., Rossignol L., Van Poucke A.
 */
public abstract class ObjModel {

    protected OBJModelLite model;
    protected PVector scale;
    protected PVector position;
    protected BoundingBoxModel boundingbox;

    /**
     * Default constructor
     * @param parent the current application 
     * @param path the path of the obj model
     * @param position the position of the obj model
     */
    public ObjModel(PApplet parent, String path, PVector position) {
        OBJModel tmp = new OBJModel(parent, path, "relative", processing.opengl.PGraphicsOpenGL.TRIANGLES);
        BoundingBox tmp2 = new BoundingBox(parent, tmp);
        this.model = tmp.setupGLCreateLite();
        this.scale = new PVector(1, 1, 1);
        this.position = position;
        this.boundingbox = new BoundingBoxModel(this.position, tmp2.getWHD(), this.scale);
    }

    /**
     * Sets the model object with a new model
     * @param model the new model to set
     */
    public void model(OBJModelLite model) {
        this.model = model;
    }

    /**
     * Returns the model 
     * @return the model 
     */
    public OBJModelLite model() {
        return this.model;
    }

    /** 
     * Sets the scale with a new scale value 
     * @param scale the new scale to set
     */
    public void scale(PVector scale) {
        this.scale = scale;
        this.boundingbox().scale(scale);
    }

    /**
     * Returns the scale 
     * @return the scale 
     */
    public PVector scale() {
        return this.scale;
    }

    /**
     * Sets the position 
     * @param position the new position to set
     */
    public void position(PVector position) {
        this.position = position;
        this.boundingbox().position(position);
    }

    /**
     * Returns the position 
     * @return the position 
     */
    public PVector position() {
        return this.position;
    }

    /**
     * Returns the bounding box 
     * @return the bounding box 
     */
    public BoundingBoxModel boundingbox() {
        return this.boundingbox;
    }

    /**
     * Abstract method draw
     * @param parent the current offscreen
     */
    public abstract void draw(OffScreen3D parent);
}